<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>筛选数组</title>
    <script>
        // var arr = [1,4,2,6,8,5,9,3]
        // var newarr = []
        // var j = 0
        // for (var i = 1; i < arr.length; i++) {
        //     if (arr[i] >= 5) {
        //         newarr[i] = arr[i]
        //         j++
        //     }
        // }
        // console.log(newarr);
        var arr = [1,4,2,0,6,8,0,5,9,30]
        var newarr = []
        var newarr1 = []
        // 刚开始 newarr.length 就是0
        for (var i = 1; i < arr.length; i++) {
            // 筛选出数组中大于5的数
            if (arr[i] >= 5) {
                newarr[newarr.length] = arr[i]
            }
            // 把数组中的0 去除
            if (arr[i] != 0) {
                newarr1[newarr1.length] = arr[i]
            }
        }
        console.log(newarr);
        console.log(newarr1);
        console.log('------');

        // 翻转数组
        var one = ['red','green','black','pink']
        var newone = []
        for (var i = one.length - 1; i >= 0; i--) {
            newone[newone.length] = one[i]
        }
        console.log(newone);
    </script>
</head>
<body>
    
</body>
</html>